<?php

require_once '../../includes/includes.php';


if (!isset($_POST['album_id'])) {
    header('Location: ../');
    exit();
}

$album_id = $_POST['album_id'];

$table = 'albums';
$fields = '*';
$where_sql = 'id = :id';
$where_data = array('id' => $album_id);

$db->select($table, $fields, $where_sql, $where_data);
$album = $db->fetch();

if ($db->rowcount() != 1) {
    echo 'There`s no such album !';
    return;
}

$dirPath = '../../albums/' . $album['name'];


// DELETE THA ALBUM FOLDER WITH CONTENTS

deleteDir($dirPath);

// DELETE THE ALBUM

$table = 'albums';
$where_sql = 'id = :id';
$where_data = array('id' => $album_id);
$db->delete($table, $where_sql, $where_data);

// DELETE THE PICS IN ALBUM

$table = 'photographs';
$where_sql = 'album_id = :album_id';
$where_data = array('album_id' => $album_id);
$db->delete($table, $where_sql, $where_data);

